package com.xh.rabbit_pay.listener;

import com.rabbitmq.client.Channel;
import com.xh.rabbit_pay.entity.Pay;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 监听订单队列，用户生成订单，存放到消息队列MQ，触发写数据库操作
 */
@Component
public class MyOrderListener {

    @RabbitListener(queues = "q.order", ackMode = "MANUAL")
    public void onMessage(Pay pay, Channel channel, Message message) throws IOException {
        System.out.println("写数据库");

        //手动确认
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

}
